package mi.payment.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import mi.payment.MyApplication;


public final class ScreenUtil {
    private static int screenW;
    private static int screenH;
    private static float screenDensity;

    static {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager manager = (WindowManager) MyApplication.app.getSystemService(Context.WINDOW_SERVICE);
        manager.getDefaultDisplay().getMetrics(metric);
        screenW = metric.widthPixels;
        screenH = metric.heightPixels;
        screenDensity = metric.density;
    }

    private ScreenUtil() {
        throw new AssertionError();
    }

    public static int getScreenW() {
        return screenW;
    }

    public static int getScreenH() {
        return screenH;
    }

    public static float getScreenDensity() {
        return screenDensity;
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dp2px(float dpValue) {
        return (int) (dpValue * screenDensity + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dp(float pxValue) {
        return (int) (pxValue / screenDensity + 0.5f);
    }
}
